import static org.junit.Assert.*;

import org.junit.Test;

import com.hamishmedlin.d64pw.FailedDecode;
import com.hamishmedlin.d64pw.Fields;
import com.hamishmedlin.d64pw.QDecoder;
import com.hamishmedlin.d64pw.QGlobals;



public class QDecoderTest {

	@Test
	public void decodeTest() throws FailedDecode {
		Fields fields = new Fields();
		fields = QDecoder.decodePassword(fields, "CXW1 TBKP 7?SK 1VK2");

		assertEquals(50, fields.getClip());
		assertEquals(true, fields.getBackback());
		assertEquals(true, fields.getChecked(QGlobals.WEAPON_CHAINGUN));
	}

	@Test
	public void failTest() {
		Fields fields = new Fields();
		try {
			fields = QDecoder.decodePassword(fields, "rvnh3ct1cd3m0???");
		} catch (FailedDecode e) {
			assertTrue(true);
		}

	}

	@Test
	public void decodeTest2() throws FailedDecode {
		Fields fields = new Fields();
		fields = QDecoder.decodePassword(fields, "1L9C 7GN5 W756 4CV?");

		assertEquals(50, fields.getClip());
		assertEquals(0, fields.getShells());
		assertEquals(0, fields.getRockets());
		assertEquals(600, fields.getCells());
		assertEquals(150, fields.getHealth());
		assertEquals(25, fields.getArmor());
		assertEquals(20, fields.getNextMap());
		assertEquals(QGlobals.SKILL_I_OWN_DOOM, fields.getGameSkill());
		
		assertEquals(true, fields.getBackback());
		
		assertEquals(true, fields.getChecked(QGlobals.WEAPON_PLASMA));
		assertEquals(true, fields.getChecked(QGlobals.WEAPON_BFG));
		assertEquals(true, fields.getChecked(QGlobals.WEAPON_LASER));
		assertEquals(true, fields.getChecked(QGlobals.ARTIFACT_DOUBLE));
		
		assertEquals(QGlobals.ARMOR_GREEN, fields.getArmorType());
		
		assertEquals(false, fields.getChecked(QGlobals.WEAPON_CHAINSAW));
		assertEquals(false, fields.getChecked(QGlobals.WEAPON_CHAINGUN));
		assertEquals(false, fields.getChecked(QGlobals.WEAPON_SHOTGUN));
		assertEquals(false, fields.getChecked(QGlobals.WEAPON_SSG));
		assertEquals(false, fields.getChecked(QGlobals.WEAPON_MISSILE));
		assertEquals(false, fields.getChecked(QGlobals.ARTIFACT_FAST));
		assertEquals(false, fields.getChecked(QGlobals.ARTIFACT_TRIPLE));
	}
}
